//SPDX-FileCopyrightText: Copyright 2025-2025 深圳市同心圆网络有限公司
//SPDX-License-Identifier: GPL-3.0-only

package gitlab_triger

import (
	"fmt"
	"testing"
)

const _ISSUE_HOOK_DATA = `
{
    "object_kind": "issue",
    "event_type": "issue",
    "user": {
        "id": 1,
        "name": "Administrator",
        "username": "root",
        "avatar_url": "https://www.gravatar.com/avatar/b4b328dfb4d8a2743e6cb237b1b82b478b11a7e317528d9e8ebb1a1d6355c4a9?s=80&d=identicon",
        "email": "[REDACTED]"
    },
    "project": {
        "id": 1,
        "name": "test·",
        "description": null,
        "web_url": "http://09b00b609eb5/g1/test",
        "avatar_url": null,
        "git_ssh_url": "git@09b00b609eb5:g1/test.git",
        "git_http_url": "http://09b00b609eb5/g1/test.git",
        "namespace": "g1",
        "visibility_level": 0,
        "path_with_namespace": "g1/test",
        "default_branch": "master",
        "ci_config_path": null,
        "homepage": "http://09b00b609eb5/g1/test",
        "url": "git@09b00b609eb5:g1/test.git",
        "ssh_url": "git@09b00b609eb5:g1/test.git",
        "http_url": "http://09b00b609eb5/g1/test.git"
    },
    "object_attributes": {
        "author_id": 1,
        "closed_at": null,
        "confidential": false,
        "created_at": "2025-02-12 07:33:28 UTC",
        "description": "xxxxx",
        "discussion_locked": null,
        "due_date": null,
        "id": 1,
        "iid": 1,
        "last_edited_at": null,
        "last_edited_by_id": null,
        "milestone_id": null,
        "moved_to_id": null,
        "duplicated_to_id": null,
        "project_id": 1,
        "relative_position": null,
        "state_id": 1,
        "time_estimate": 0,
        "title": "xxxx",
        "updated_at": "2025-02-12 07:33:28 UTC",
        "updated_by_id": null,
        "type": "Issue",
        "url": "http://09b00b609eb5/g1/test/-/issues/1",
        "total_time_spent": 0,
        "time_change": 0,
        "human_total_time_spent": null,
        "human_time_change": null,
        "human_time_estimate": null,
        "assignee_ids": [],
        "assignee_id": null,
        "labels": [],
        "state": "opened",
        "severity": "unknown",
        "customer_relations_contacts": [],
        "action": "open"
    },
    "labels": [],
    "changes": {
        "author_id": {
            "previous": null,
            "current": 1
        },
        "created_at": {
            "previous": null,
            "current": "2025-02-12 07:33:28 UTC"
        },
        "description": {
            "previous": null,
            "current": "xxxxx"
        },
        "id": {
            "previous": null,
            "current": 1
        },
        "iid": {
            "previous": null,
            "current": 1
        },
        "project_id": {
            "previous": null,
            "current": 1
        },
        "title": {
            "previous": null,
            "current": "xxxx"
        },
        "updated_at": {
            "previous": null,
            "current": "2025-02-12 07:33:28 UTC"
        }
    },
    "repository": {
        "name": "test·",
        "url": "git@09b00b609eb5:g1/test.git",
        "description": null,
        "homepage": "http://09b00b609eb5/g1/test"
    }
}
`

func TestExtractIssueHookAttr(t *testing.T) {
	attrList, err := ExtractIssueHookAttr([]byte(_ISSUE_HOOK_DATA))
	if err != nil {
		t.Fatal(err)
		t.FailNow()
	}
	fmt.Println(attrList)
}
